home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************/
- /* */
- /* This C compiler is copied from Dr. Dobb's Journal of Computer */
- /* Calisthenics & Orthodontia (issue number 45) */
- /* -- Distribution and use is unrestricted for non-commercial use. */
- /* */
- /* RAF 8-8-80 */
- /* */
- /*********************************************************************/
-
- /************************************************/
- /* */
- /* small-c compiler */
- /* rev. 1.1 */
- /* by Ron Cain */
- /* */
- /************************************************/
-
- /* Define system dependent parameters */
-
- /* Stand-alone definitions */
-
- #define BUFSIZ 1030
- #define ERROR -1
- #define FALSE 0
- #define TRUE 1
- #define eol 13
- #define CR 13
- #define LF 10
- #define BS 8
- #define TB 9
- #define FF 12
-
- /* Define symbol table parameters */
- #define lvalsize 3
- #define SWITCH_MAX 254
- #define symsiz 15
- #define symtbsz 6000
- #define numglbs 300
- #define startglb symtab
- #define endglb startglb+numglbs*symsiz
- #define startloc endglb+symsiz
- #define endloc symtab+symtbsz-symsiz
-
- /* Define symbol table entry format */
-
- #define name 0
- #define ident 9
- #define type 10
- #define indcnt 11
- #define storage 12
- #define offset 13
- #define offset1 14
- /* System wide name size (for symbols) */
-
- #define namesize 9
- #define namemax 8
-
- /* Define possible entries for "ident" */
-
- #define variable 1 /* a normal varble */
- #define array 2 /* array of varbles */
- #define pointer 3 /* pointer to a varble */
- #define function 4 /* entry is a function */
- /* Define possible entries for "type" */
-
- #define cchar 1
- #define cint 2
-
- /* Lenght of possible entries for "type" */
-
- #define lchar 1
- #define lint 2
- #define lpoint 2
-
- /* Define possible entries for "storage" */
-
- #define statik 1
- #define stkloc 2
- #define stkarg 3
-
- /* values returned by heirxx */
-
- #define LOADED 0 /* value on top of stack */
- #define ADDRESS 1 /* address of lvalue on stack */
- #define NOTLOADED 2 /* address in lvalue in array not loaded */
- #define CONSTANT 3 /* constant in lval */
- /* Define the "while" statement queue */
-
- #define wqtabsz 100
- #define wqsiz 6
- #define wqmax wq+wqtabsz-wqsiz
-
- /* Define entry offsets in while queue */
-
- #define wqsym 0
- #define wqsp 1
- #define wqloop 2
- #define wqlab 3
- #define wqend 4
- #define wqbody 5
- /* Define the literal pool */
-
- #define litabsz 2000
- #define litmax litabsz-1
-
- /* Define the input line */
-
- #define linesize 80
- #define linemax linesize-1
- #define mpmax linemax
-
- /* Define the macro (define) pool */
-
- #define macqsize 1000
- #define macmax macqsize-1
-
- /* Define statement types (tokens) */
-
- #define stif 1
- #define stwhile 2
- #define stfor 3
- #define stswitch 4
- #define streturn 5
- #define stbreak 6
- #define stcont 7
- #define stasm 8
- #define stexp 9
-
- /* name of some function called by code gen step */
-
- #define EQ "@comp"
- #define GE "@comp+25h"
- #define GT "@comp+12h"
- #define LE "@comp+2fh"
- #define LT "@comp+1ch"
- #define NE "@comp+19h"
-
- #define UGE "@ucomp+13h"
- #define UGT "@ucomp"
- #define ULE "@ucomp+1ch"
- #define ULT "@ucomp+0ah"
-
- #define PREINC "@incdec"
- #define PREDEC "@incdec+08h"
- #define POSTINC "@incdec+10h"
- #define POSTDEC "@indec+1ah"
-
- /* Now reserve some storage words */
-
- char symtab[symtbsz]; /* symbol table */
- char *glbptr,*locptr; /* ptrs to next entries */
- int wq[wqtabsz]; /* while queue */
- int *wqptr; /* ptr to next entry */
-
- char litq[litabsz]; /* literal pool */
- int litptr; /* ptr to next entry */
-
- char macq[macqsize]; /* macro string buffer */
- int macptr; /* and its index */
-
- char line[linesize]; /* parsing buffer */
- char mline[linesize]; /* temp macro buffer */
- int lptr,mptr; /* ptrs into each */
-
- /* Misc storage */
-
- int nxtlab, /* next avail label # */
- litlab, /* label # assigned to literal pool */
- sp, /* compiler relative stk ptr */
- argstk, /* function arg sp */
- ncmp, /* # open compound statements */
- errcnt, /* # errors in compilation */
- eof, /* set non-zero on final input eof */
- input, /* iob # for input file */
- output, /* iob # for output file (if any) */
- input2, /* iob # for "include" title */
- line1, /* current line number in main file */
- line2, /* current line in include file */
- ctext, /* non-zero to intermix c-source */
- cmode, /* non-zero while parsing c-code */
- /* zero when passing assembly code */
- cif, /* state of preprocess if statement */
- lastst; /* last executed statment type */
-
- char *cptr; /* work ptr to any char buffer */
- int *iptr; /* work ptr to any int buffer */
- /* file io buffers */
- char finp[BUFSIZ]; /* input file buffer */
- char finp2[BUFSIZ]; /* input 2 file buffer */
- char fout[BUFSIZ]; /* ouput file buffer */
- n&